layui.use(['layer', 'table', 'ax', 'laydate'], function () {
    var $ = layui.$;
    var $ax = layui.ax;
    var layer = layui.layer;
    var table = layui.table;
    var laydate = layui.laydate;

    /**
     * 系统管理--登陆日志
     */
    var LoginLog = {
        tableId: "loginLogTable"   //表格id
    };

    /**
     * 初始化表格的列
     */
    LoginLog.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, sort: true, title: 'id'},
            {field: 'logName', sort: false, title: '日志名称'},
            {field: 'loginName', sort: false, title: '登录名'},
            {field: 'logStatus', sort: false, title: '状态'},
            {field: 'logDetail', sort: false, title: '日志描述'},
            {field: 'uaAgent', sort: false, title: 'UA'},
            {field: 'ip', sort: false, title: 'IP'},
            {field: 'createTime', sort: true, title: '日志时间'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    LoginLog.search = function () {
        var queryData = {};
        queryData['beginTime'] = $("#beginTime").val();
        queryData['endTime'] = $("#endTime").val();
        queryData['loginName'] = $("#loginName").val();
        table.reload(LoginLog.tableId, {where: queryData});
    };


    //渲染时间选择框
    laydate.render({
        elem: '#beginTime'
    });

    //渲染时间选择框
    laydate.render({
        elem: '#endTime'
    });

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + LoginLog.tableId,
        url: Sam.ctxPath + '/sam/loginlog/list',
        page: true,
        toolbar: true,
        height: "full-98",
        cellMinWidth: 100,
        cols: LoginLog.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        LoginLog.search();
    });
});
